package edu.washington.cs.sounddetector.server.api.methodresult;

import java.util.List;
import java.util.Map;

import edu.washington.cs.sounddetector.server.api.MethodResult;
import edu.washington.cs.sounddetector.server.api.method.GetSounds;
import edu.washington.cs.sounddetector.server.api.object.SoundClass;

public class GetSoundsResult extends MethodResult<GetSounds>
{
    private Map<SoundClass, List<Long>> sounds;
    private String detectorId;

    private GetSoundsResult(boolean successful, FailureReason reason,
            Map<SoundClass, List<Long>> sounds, String detectorId)
    {
        super(successful, reason);
        this.sounds = sounds;
        this.detectorId = detectorId;
    }

    private GetSoundsResult()
    {
        this(true, null, null, null);
    }

    /**
     * @return if {@link #isSuccessful()} is true, returns a map from sound classes to a list of
     *         sound ids, otherwise returns null
     */
    public Map<SoundClass, List<Long>> getSounds()
    {
        return sounds;
    }

    /**
     * @return if {@link #isSuccessful()} is false, returns the detector id that does not exist,
     *         otherwise returns null
     */
    public String getDetectorId()
    {
        return detectorId;
    }

    public static GetSoundsResult success(Map<SoundClass, List<Long>> sounds)
    {
        return new GetSoundsResult(true, null, sounds, null);
    }

    public static GetSoundsResult failureDetectorIdDoesNotExist(String detectorId)
    {
        return new GetSoundsResult(false, FailureReason.DETECTOR_ID_DOES_NOT_EXIST, null,
                detectorId);
    }

}
